package com.lakers.notice.springboot.netty.processor;

import cn.hutool.core.bean.BeanUtil;
import com.lakers.notice.springboot.model.NoticeHeartbeatInfo;
import com.lakers.notice.springboot.netty.CmdType;
import com.lakers.notice.springboot.netty.SendInfo;
import io.netty.channel.ChannelHandlerContext;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.HashMap;

/**
 * 功能描述: HeartbeatProcessor
 *
 * @author liqin(zxl)
 * @date 2024/5/3
 */
@Slf4j
@Component
public class HeartbeatProcessor extends AbstractMessageProcessor<NoticeHeartbeatInfo>{

    @Override
    public void process(ChannelHandlerContext ctx, NoticeHeartbeatInfo data) {
        SendInfo<Void> sendInfo = new SendInfo<>();
        sendInfo.setCmd(CmdType.HEART_BEAT.getCmd());
        ctx.channel().writeAndFlush(sendInfo);

    }
    @Override
    public NoticeHeartbeatInfo transForm(Object o) {
        HashMap map = (HashMap) o;
        return BeanUtil.fillBeanWithMap(map, new NoticeHeartbeatInfo(), false);
    }

}
